﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Input;
using WPFExcelReport.Helpers;
using System.Windows.Controls;
namespace WPFExcelReport
{
    public partial class TEXORD
    {
    

        public TEXORD()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_EXORD();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {

            try
            {
                if (IsLoaded)
                    return;
                base.Window_Loaded(sender, e);
                ModeEdit = false;
                txtUser.Text = app.User;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }

        DataTable TBResult;
        private void btnAddVKP_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (VAR.Trim() == "")
                {
                    MessageBox.Show("Please mark your Brand:!");
                    return;
                }

                if (!ModeEdit)
                {
                    SaveCommand(null, null);
                    cVK.GETORD();
                    pos = 1;
                    TBMain.Clear();
                } 
                ModeEdit = false;
                NewVKP(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }

        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
           // base.SaveCommand(sender, e);
            try
            { 
                PM["LFD"] = MAXORD;             
                TMV.SAVEVKP(PM);   
            } 
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message);
            }
        }
    
        public override void OnEXAUFChg(string vlaue)
        {
            try
            {
                TBMain.Clear();
                if (EXAUF.Length < 2)
                    return;
                TMV.sql = "SELECT * FROM ICC_EXORD WHERE VKPAUFKRS = '" + EXAUF.Substring(0, 2).Trim() + "' AND VKPAUFLFD='" + EXAUF.Substring(2, 6).Trim() + "'";
                TBResult = TMV.SQLiteDatabase.GetDataTable(TMV.sql);
                TBMain.Merge(TBResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            base.OnEXAUFChg(vlaue);
        }

       

        private void txtRemark_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key != System.Windows.Input.Key.Enter)
                return;
            if (e.Key != System.Windows.Input.Key.Return)
                return;
            txtNart.Focus();
            vwMaster.View.MoveCurrentToFirst();
        }
    }
}